NS_ENABLE_TAINT=1;
var intervalo="";
$(document).ready(function() {

	/*$.history.init(function(url) {
		load(url);
	});*/
	$(window).bind("beforeunload",function(event) {
        window.location.href=$("#contexto_spring").attr("title")+"deslogeo";
     //  alert("Por su Seguridad, su sesion ha finalizado!!");
       // return;
	});
	
	$('#basicclock').clock();
	$('#clock_session').countdown({until: '+00m +'+$('#temp_sess').html()+'s', format: 'MS', significant: 2,compact: true,onExpiry: valida_session,expiryText: 'Sesion caducada'}); 
	
	$('a.remoto').live('click', function(e) {
		var url = $(this).attr('href');
		url = url.replace(/^.*#/, '');
		//$.history.load(url);
		 cargar(url);
			return false;
		});

	$('a.operacion_remota').live('click', function(e) {
		var url = $(this).attr('href');
		url = url.replace(/^.*#/, '');
		cargarOperacionRemota(url);
		return false;
	});

	var container = $('body'), west = $('body > .west'), east = $('body > .east'), center = $('body > .center');
	
	function layout() {
		container.layout();
		$('#accordion').accordion('resize');
		west.resizable('option', 'minWidth', 200);
		//west.resizable('option', 'maxWidth',(center.width() + west.width()) - 500);
		west.resizable('option', 'maxWidth', (center.width() + west.width()) - 400);
	}

	west.resizable( {
		handles : 'e',
		stop : layout,
		minWidth : 200
	});
	$("#progressbar").progressbar({
		value: 59
	});

	$('#datepicker').datepicker();
	layout();
	$(window).resize(layout);
	
	var icons = {
			header: "ui-icon-circle-arrow-e",
			headerSelected: "ui-icon-circle-arrow-s"
		};
	
	$('#accordion').accordion(
					{
						header : 'h3',
						fillSpace : true,
						icons : icons,
						autoHeight: false,
						/*collapsible: true,*/
						change : function(event, ui) {
							$('.ui-corner-all,.ui-corner-top').removeClass('ui-corner-all ui-corner-top');
							if(ui.newHeader.children('a').attr("title")){
								//$('#muestra').slideUp();
								$('#muestra').hide();
								$('#muestra').load("acceso_sistema_admin",{sistema : ui.newHeader.children('a').attr("title")});
								$('#muestra').ajaxStop(function() {$(this).slideDown();});
							}
							else{
								//$('#muestra').slideUp();
								$('#muestra').hide();
								$('#muestra').html("");
							}
						}
					});
	$('#accordion').accordion({ active: 1 });

	$.extend($.ui.slider.defaults, {
		range : "min",
		animate : true,
		orientation : "vertical"
	});

	$("#eq > span").each(function() {
		var value = parseInt($(this).text());
		$(this).empty();
		$(this).slider( {
			value : value
		});
	});

	$(".trio").dynatree({
		// autoCollapse: true,
		fx : {
			height : "toggle",
			duration : 200
		},
		minExpandLevel : 1,
		onClick : function(node) {
		if (node.data.href) {
			var url = node.data.href;
			url = url.replace(/^.*#/, '');
			var ind = url.indexOf('.dialog');
			if (ind <= 0) {
				//$.history.load(url);
				cargar(url);
			} else {
				var cadena_dimensiones = url.substring(url.indexOf('[') + 1,url.length - 1);
				var dimensiones = ($.trim(cadena_dimensiones)).split(',');
				url = url.substring(0, url.indexOf('.dialog'));
				Utiles_MensajesDialogo.showRequestDialogMinimizable(node.data.title,url + ".htm",parseInt(dimensiones[0]),parseInt(dimensiones[1]));
			}
			//node.deactivate();
			return false;
		}
	}
		});
	
	 $('body').ajaxStop(function() {
		 //$.log("%s is %d years old."+$('#basicclock').html(), "Bob", intervalo);
		 $('#clock_session').countdown('change',{until: '+00m +'+$('#temp_sess').html()+'s'}); 
	    });
});
